package com.mocha.bss.domain.rbac.repository;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mocha.bss.domain.rbac.repository.mapper.MochaRoleFunctionMapper;
import com.mocha.bss.domain.rbac.repository.entity.RoleFunctionEntity;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author songkui
 * @since 2022-03-11
 */
@Service
public class MochaRoleFunctionRepository extends ServiceImpl<MochaRoleFunctionMapper, RoleFunctionEntity>  {

    public List<RoleFunctionEntity> listByRoleIds(List<Long> roleIds){
        return this.lambdaQuery().select(RoleFunctionEntity::getFunctionCode).in(RoleFunctionEntity::getRoleId, roleIds).list();
    }

    public String functionCodeByRoleId(Long roleId){
        List<RoleFunctionEntity> list = this.lambdaQuery().select(RoleFunctionEntity::getFunctionCode).eq(RoleFunctionEntity::getRoleId, roleId).list();
        return CollectionUtil.isNotEmpty(list) ? list.get(0).getFunctionCode() : null;
    }



}

